package com.eric.text;

import java.util.List;

import org.ansj.app.summary.SummaryComputer;
import org.ansj.app.summary.pojo.Summary;
import org.jsoup.nodes.Document;

import com.eric.utils.TextUtils;
import com.eric.utils.page.ArticleExtractor;
import com.eric.utils.page.IR;

public class AnsjSummaryWorker extends AbstractTextWorker {

	public AnsjSummaryWorker(Object input) {
		super(input);
	}

	@Override
	public void produce() {
		init();
		initThis();
		// SummaryComputer summaryComputer = new SummaryComputer(sumNum,
		// doc.title(), text);
		// Summary sum = summaryComputer.toSummary();
		// result.add(sum.getSummary());
		if (IR.isArticlePage(doc)) {
			ArticleExtractor ex = new ArticleExtractor(doc);
			ex.removeStopWords();
			String content = ex.extract();

			result.add(getSummary(sumNum, doc.title(), content));
		} else {
			result.add("不是文章页!");
		}
	}

	@Override
	public List<String> produce(String text, Document doc) {
		return null;
	}

	@Override
	protected void initThis() {

	}

	@Override
	public List<String> getContext() {
		return null;
	}

	public String getSummary(int len, String title, String content) {
		StringBuilder sb = new StringBuilder();
		SummaryComputer summaryComputer = new SummaryComputer(len, title, content);
		Summary sum = summaryComputer.toSummary();
		String s = sum.getSummary();
		// sb.append(TextUtils.firstSentence(content));

		sb.append(TextUtils.trimSubString(s, content));
		// sb.append(s);

		return sb.toString();
	}

}
